package com.googlecode.bushel.obr.filter;

import com.googlecode.bushel.obr.xml.RequirementFilter;

public abstract class UniOperatorFilter extends RequirementFilter {

    private final RequirementFilter subFilter;

    public UniOperatorFilter(RequirementFilter subFilter) {
        this.subFilter = subFilter;
    }

    abstract protected char operator();

    @Override
    public void append(StringBuilder builder) {
        builder.append("(");
        builder.append(operator());
        builder.append(subFilter.toString());
        builder.append(")");
    }

    public RequirementFilter getSubFilter() {
        return subFilter;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((subFilter == null) ? 0 : subFilter.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof MultiOperatorFilter)) {
            return false;
        }
        UniOperatorFilter other = (UniOperatorFilter) obj;
        if (subFilter == null) {
            if (other.subFilter != null) {
                return false;
            }
        } else if (!subFilter.equals(other.subFilter)) {
            return false;
        }
        return true;
    }
}
